home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 7661 / 7661.xpi / chrome / isreaditlater.jar / content / offlineAction.xul < prev    next >
Extensible Markup Language  |  2009-10-12  |  6KB  |  217 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!DOCTYPE window SYSTEM "chrome://isreaditlater/locale/isreaditlater.dtd">
  4.  
  5. <?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
  6. <?xml-stylesheet href="chrome://isreaditlater/skin/ril.css" type="text/css"?>
  7.  
  8.  
  9.  
  10.  
  11. <dialog id="RIL_offlineAction"
  12.         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  13.         title="Loading..."
  14.         buttons="cancel"
  15.         ondialogaccept="return canCancel();"
  16.         ondialogcancel="return canCancel();"
  17.         onload="setTimeout(perform,333)"
  18.         persist="screenX screenY">
  19.     
  20.     
  21.     <label>Depending on how many files you have, this might take a while.</label>
  22.     <progressmeter mode="undetermined"/>
  23.                 
  24.     
  25.     <stringbundleset id="stringbundleset">
  26.     <stringbundle id="isRitL-strings" src="chrome://isreaditlater/locale/jsstrings.properties"/>
  27.     </stringbundleset>
  28.     
  29.     <script type="application/x-javascript">
  30.         var thread, action, newFolder;
  31.         var APP, ASSETS;
  32.         
  33.         function perform()
  34.         {
  35.             action = window.arguments[0];
  36.             
  37.             APP = Components.classes['@ril.ideashower.com/rildelegate;1'].getService().wrappedJSObject;
  38.             ASSETS = Components.classes['@ril.ideashower.com/rilassetmanager;1'].createInstance(Components.interfaces.nsIRILassetManager);
  39.             ASSETS.init();
  40.             
  41.             if ( APP.OFFLINE.clearingOffline || APP.OFFLINE.movingOffline )
  42.             {
  43.                 // not allowed to do more than one at a time
  44.                 return window.close();
  45.             }
  46.             
  47.             switch(action)
  48.             {
  49.                 case('clearing'):
  50.                     title = 'Clearing Offline Files...';
  51.                     clearOffline();
  52.                     break;
  53.                 case('moving'):
  54.                     title = 'Moving Offline Files...';
  55.                     moveOffline();
  56.                     break;
  57.                 default:
  58.                     return window.close();
  59.                     break;
  60.             }
  61.         
  62.             document.getElementById('RIL_offlineAction').setAttribute('title', title);
  63.         }
  64.         
  65.         
  66.         function clearOffline()
  67.         {
  68.             // stop the queue if it is running
  69.             APP.OFFLINE.cancel();
  70.             
  71.             // Clear
  72.             APP.OFFLINE.setOfflineStatus('clearing', true);
  73.             
  74.             APP.LIST.resetOffline();
  75.             clearThread.DIR_PAGES = ASSETS.DIR_PAGES;
  76.             clearThread.DIR_ASSETS = ASSETS.DIR_ASSETS;            
  77.             
  78.             thread = Components.classes["@mozilla.org/thread-manager;1"].getService().newThread(0);
  79.             thread.dispatch(clearThread, thread.DISPATCH_NORMAL);
  80.             
  81.         }
  82.         
  83.         
  84.         function moveOffline()
  85.         {            
  86.             APP.OFFLINE.setOfflineStatus('moving', true);
  87.             
  88.             let close = false;
  89.             newFolder = movingThread.newFolder = window.arguments[1];
  90.             
  91.             let newPathPages = newFolder.path + ASSETS.FD + ASSETS.PAGES_FOLDER_NAME;        
  92.             let newPathAssets = newFolder.path + ASSETS.FD + ASSETS.ASSETS_FOLDER_NAME;
  93.             let newPages = APP.ASSETS.file(newPathPages);
  94.             let newAssets = APP.ASSETS.file(newPathAssets);
  95.             
  96.             if (!newPages.exists())
  97.             {
  98.                 if (!newAssets.exists())            
  99.                 {            
  100.                     let thread = Components.classes["@mozilla.org/thread-manager;1"].getService().newThread(0);
  101.                     thread.dispatch(movingThread, thread.DISPATCH_NORMAL);
  102.                 }
  103.             }
  104.             else
  105.             {
  106.                 // if they do already contain asset folders, flush offline settings of all items (and rebuild by scanning)
  107.                 APP.LIST.resetOffline();
  108.                 
  109.                 // #beta2 start scanning new folder in a thread for files #beta (also update downloader to check for web.html and text.html)
  110.                 
  111.                 APP.OFFLINE.setOfflineStatus('moving', false);
  112.             
  113.                 // set new directory
  114.                 APP.PREFS.set('offlinePath', newFolder.path);
  115.                 
  116.                 if (close) window.close();
  117.             }
  118.             
  119.         }
  120.         
  121.         function canCancel()
  122.         {
  123.             try {
  124.                 thread.shutdown();
  125.             } catch(e) {
  126.                 Components.utils.reportError(e);
  127.             }
  128.             
  129.             return true;
  130.         }
  131.         
  132.         clearThread = {
  133.             
  134.             run : function()
  135.             {
  136.                 try {
  137.                 
  138.                 try {
  139.                     this.DIR_PAGES.remove(true);
  140.                     this.DIR_ASSETS.remove(true);                
  141.                 } catch(e) {Components.utils.reportError(e);}
  142.                 
  143.                 var main = Components.classes["@mozilla.org/thread-manager;1"].getService().mainThread;
  144.                 main.dispatch(new mainThread(), this.DISPATCH_NORMAL);                
  145.                 
  146.                 } catch(e) {Components.utils.reportError(e);}
  147.             },
  148.         
  149.             QueryInterface: function(iid)
  150.             {
  151.                 if (iid.equals(Components.interfaces.nsIRunnable) ||
  152.                     iid.equals(Components.interfaces.nsISupports)) {
  153.                     return this;
  154.                 }
  155.                 throw Components.results.NS_ERROR_NO_INTERFACE;
  156.             }
  157.         
  158.         }
  159.         
  160.         movingThread = {
  161.             
  162.             run : function()
  163.             {
  164.                 try {
  165.                     let ASSETS = Components.classes['@ril.ideashower.com/rilassetmanager;1'].createInstance(Components.interfaces.nsIRILassetManager);
  166.                     ASSETS.init();
  167.                 
  168.                     try {
  169.                         ASSETS.DIR_PAGES.moveTo( this.newFolder, null );
  170.                         ASSETS.DIR_ASSETS.moveTo( this.newFolder, null );        
  171.                     } catch(e) {Components.utils.reportError(e);}
  172.                 
  173.                     var main = Components.classes["@mozilla.org/thread-manager;1"].getService().mainThread;
  174.                     main.dispatch(new mainThread(), this.DISPATCH_NORMAL);                
  175.                 
  176.                 } catch(e) {Components.utils.reportError(e);}
  177.             },
  178.         
  179.             QueryInterface: function(iid)
  180.             {
  181.                 if (iid.equals(Components.interfaces.nsIRunnable) ||
  182.                     iid.equals(Components.interfaces.nsISupports)) {
  183.                     return this;
  184.                 }
  185.                 throw Components.results.NS_ERROR_NO_INTERFACE;
  186.             }
  187.         
  188.         }
  189.         
  190.         function mainThread() {}
  191.         mainThread.prototype = {
  192.             
  193.             run: function()
  194.             {
  195.                 if (action == 'moving')                
  196.                     APP.PREFS.set('offlinePath', newFolder.path);
  197.                     
  198.                 APP.OFFLINE.setOfflineStatus(action, false);
  199.                 
  200.                 window.close();
  201.             },
  202.             
  203.             QueryInterface: function(iid) {
  204.                 if (iid.equals(Components.interfaces.nsIRunnable) ||
  205.                     iid.equals(Components.interfaces.nsISupports)) {
  206.                     return this;
  207.                 }
  208.                 throw Components.results.NS_ERROR_NO_INTERFACE;
  209.             }
  210.             
  211.         }
  212.  
  213.         
  214.     </script>
  215.     
  216. </dialog>
  217.